package com.egg.ylt.presenter.impl;

import com.egg.ylt.Utils.API;
import com.egg.ylt.pojo.UploadPhotoEntity;
import com.egg.ylt.presenter.IHealthPresenter;
import com.egg.ylt.view.IHealthView;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.CommonUtils;
import com.yonyou.framework.library.mvp.impl.BasePresenter;
import com.yonyou.framework.library.net.ReqCallBack;
import com.yonyou.framework.library.net.RequestManager;

import java.io.File;
import java.util.HashMap;

/**
 * sichaoqi on 2018/12/13
 */
public class FraHealthImpl extends BasePresenter<IHealthView> implements IHealthPresenter {
    @Override
    public void upLoadPhoto(String imgUrl) {
        mView.showDialogLoading("数据加载中");
        HashMap<String, Object> hashMap = new HashMap<>();
        File photoFile = new File(imgUrl);
        hashMap.put("file", photoFile);
        RequestManager.getInstance().upLoadFile(API.POST_UPLOAD_PHOTO, hashMap, new ReqCallBack<UploadPhotoEntity>() {

            @Override
            public void onReqSuccess(UploadPhotoEntity result) {
                mView.dismissDialogLoading();
                mView.upLoadSucceed(result);
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }

    @Override
    public void saveDiaryPhoto(String token, String companyId, String imageUrl, String thumbnailUrl) {
//        mView.showDialogLoading("数据加载中");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("token", token);
        hashMap.put("companyId", companyId);
        hashMap.put("imageUrl", imageUrl);
        hashMap.put("thumbnailUrl", thumbnailUrl);
        RequestManager.getInstance().requestPostByAsyn(API.POST_SAVE_DIARY_PHOTO, hashMap, new ReqCallBack<String>() {

            @Override
            public void onReqSuccess(String result) {
                mView.dismissDialogLoading();
                mView.saveDiarySucceed();
            }

            @Override
            public void onFailure(String result) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, result, false);
            }

            @Override
            public void onReqFailed(ErrorBean error) {
                mView.dismissDialogLoading();
                CommonUtils.makeEventToast(mContext, error.getMsg(), false);
            }
        });
    }
}
